#include <bits/stdc++.h>
using namespace std;
int T,L,V,n,m,tot,d[100005],v[100005],a[100005],p[100005],t[1000005],del[100005],ans1,ans2;
struct q{
    int x,y;
} g[100005];
bool cmp(q s1,q s2){
    if(s1.x==s2.x) return s1.y>s2.y;
    else return s1.x<s2.x;
}
int lowbit(int x){
    return x&-x;
}
void in(int x,int l){
    while(x<=l){
        t[x]++;
        x+=lowbit(x);
    }
}
int query(int x){
    int sum=0;
    while(x>=0){
        sum+=t[x];
        if(x==0) break;
        x-=lowbit(x);
    }
    return sum;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        ans1=ans2=0;
        scanf("%d%d%d%d",&n,&m,&L,&V);
        memset(t,0,sizeof(t));
        for(int i=1;i<=n;i++){
            scanf("%d%d%d",&d[i],&v[i],&a[i]);
        }
        for(int i=1;i<=m;i++){
            scanf("%d",&p[i]);
            in(p[i],L);
        }
        sort(p+1,p+m+1);
        int z=-1;
        tot=0;
        for(int i=1;i<=n;i++){
            if(a[i]==0){
                if(v[i]>V&&p[m]>=d[i]){
                    ans1++;
                    z=max(z,d[i]);
                }
            }
            else if(a[i]>0){
                if(v[i]>V){
                    if(p[m]>=d[i]){
                        z=max(z,d[i]);
                        ans1++;
                    }
                }
                else{
                    int tmp=(V*V-v[i]*v[i])/(2*(a[i]))+1;
                    if(p[m]>=d[i]+tmp){
                        z=max(z,d[i]+tmp);
                        ans1++;
                    }
                }
            }
            else{
                if(v[i]<=V) continue;
                else{
                    int tmp=(V*V-v[i]*v[i])/(2*(a[i]))-((V*V-v[i]*v[i])%(2*(a[i]))==0);
                    if(query(min(L,d[i]+tmp))-query(d[i]-1)){
                        ans1++;
                        tot++;
                        g[tot]={d[i],min(L,d[i]+tmp)};
                    }
                }
            }
        }
        printf("%d ",ans1);
        if(z!=-1){
            tot++;
            g[tot]={z,L};
        }
        memset(del,0,sizeof(del));
        int minn=L+1;
        sort(g+1,g+tot+1,cmp);
        for(int i=tot;i>=1;i--){
            if(minn<g[i].y) del[i]=1;
            else minn=min(minn,g[i].y);
        }
        int maxn=-1,s=1;
        for(int i=1;i<=tot;i++){
            if(del[i]!=0) continue;
            if(maxn>=g[i].x) continue;
            while(s<m&&p[s+1]<=g[i].y){
                s++;
            }
            maxn=p[s];
            ans2++;
        }
        printf("%d\n",m-ans2);
    }
    return 0;
}
